package com.anlogic.sdk.openocd.ui;

import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

import com.anlogic.sdk.openocd.model.JtagCable;

public class ScanUsbDialog extends TitleAreaDialog{
	private MultiCableDevicesWidget multiCableDevices;
	
	public ScanUsbDialog(Shell parentShell) {
		super(parentShell);
		setShellStyle(getShellStyle() | SWT.RESIZE);
		
	}
	
	protected Control createDialogArea(Composite parent) {
		setTitle("Scan Jtag Devices");

		Composite container = new Composite(parent, SWT.DEFER);
		container.setLayout(new GridLayout(1, false));
		container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		
		multiCableDevices = new MultiCableDevicesWidget(container);
		
		return (Control) parent;
	}
	
	public Composite getContainer() {
		return multiCableDevices.getContainer();
	}
	
	public void setEnable(boolean enabled) {
		getContainer().setEnabled(enabled);
		for (Control c : getContainer().getChildren()) {
			c.setEnabled(enabled);
		}
	}
	
	public JtagCable getSelecionCable() {
		return multiCableDevices.getSelecionCable();
	}
	
	protected void okPressed() {
		multiCableDevices.savePreferences();
		super.okPressed();
	}
}
